package com.global.college.ui.presenter;

import android.content.Context;

import com.global.college.api.ProgressSubscriber;
import com.global.college.base.BasePresenter;
import com.global.college.data.net.MyCourseListBean;
import com.global.college.ui.interfaces.ICourseView;

/**
 * 课程
 */
public class CoursePresenter extends BasePresenter {

    private ICourseView mICourseView;

    public CoursePresenter(Context context) {
        super(context);
    }

    public void setCourseView(ICourseView courseView){
        mICourseView = courseView;
    }

    /**
     * 课程列表
     * @param
     */
    public void getCourseList(int pageNum, int pageSize, int type){
        mRequestClient.getCourseList( pageNum,  pageSize, type).subscribe(new ProgressSubscriber<MyCourseListBean>(mContext,true) {
            @Override
            public void onNext(MyCourseListBean object) {
                if(null != mICourseView){
                    mICourseView.onCourseListSuccess(object);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mICourseView){
                    mICourseView.onCourseListFail(e.getMessage());
                }
            }
        });
    }

    /**
     * 课程详情
     * @param
     */
    public void getCourseDetail(String classId){
        mRequestClient.getCoursesDetail(classId).subscribe(new ProgressSubscriber<Object>(mContext,true) {
            @Override
            public void onNext(Object smsModel) {
                if(null != mICourseView){
                    mICourseView.onCourseDetailSuccess(smsModel);
                }
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mICourseView){
                    mICourseView.onCourseDetailFail(e.getMessage());
                }
            }
        });
    }

}
